package com.wealth.commodity.web.controller;

import iaas.utils.ResultObject;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wealth.commodity.enums.GoodsStatusEnum;
import com.wealth.commodity.service.IGoodsService;
import com.wealth.commodity.vo.GoodsVO;
import com.wealth.merchant.entity.Merchant;
import com.wealth.merchant.service.IMerchantService;
import com.wealth.system.web.controller.BaseController;


/**
 * @author xf
 *	打折商品
 */
@Controller
@RequestMapping(value="/discountGoogs")
public class DiscountGoodsController extends BaseController{
	
	
	Logger logger = Logger.getLogger(DiscountGoodsController.class);
	@Autowired
	private IGoodsService goodsService;
	@Autowired
	private IMerchantService merchantService;

	//打折商品首页
	@RequestMapping(value="/index")
	public String index(Model model){
		try {
			
			
			return "discount/index";
		} catch (Exception e) {
			logger.error("特价商品列表错误", e);
			return "system/500";
		}
	}
	
	
	//查询打折商户
	@RequestMapping(value="/merchantShow",method=RequestMethod.POST)
	@ResponseBody
	public ResultObject more(Long maxId) {
		try{
			//   1 是否打折标志标志  
			List<Merchant> merchants=merchantService.getDiscountGoods(1, maxId);
			return new ResultObject("000", "加载成功", merchants);
			
		}catch(Exception e){
			return new ResultObject("999", "加载错误", "");
		}
	}
	
	
	//查询打折商户的所有商品列表
	@RequestMapping(value="/merchantinfoShow",method=RequestMethod.POST)
	@ResponseBody
	public ResultObject merchantinfoShow(Long maxId,Long merchantId) {
		try{
			
			//1 是否打折标志
			List<GoodsVO> goodsVOs=goodsService.findByMerchantIdAndIsDiscountAndStatus(maxId,merchantId, 1, GoodsStatusEnum.UP.getValue());
			return new ResultObject("000", "加载成功", goodsVOs);
			
		}catch(Exception e){
			e.printStackTrace();
			return new ResultObject("999", "加载错误", "");
		}
	}
		
	//跳转页面
	@RequestMapping(value="/info",method=RequestMethod.GET)
	public String info(Model model,Long merchantId){
		try {
			model.addAttribute("merchantId", merchantId);
			return "discount/info";
		} catch (Exception e) {
			logger.error("特价商品列表错误", e);
			return "system/500";
		}
	}

}
